package apps.sim.action.handler;

import java.util.List;
import java.util.Map.Entry;
import java.util.Set;

import apps.sim.core.AHandler;

import com.sun.net.httpserver.Headers;
import com.sun.net.httpserver.HttpExchange;

public class RequestHeadersHandler extends AHandler {

	@Override
	public byte[] handle(HttpExchange exchange, String context) throws Exception {
		final Headers requestHeaders = exchange.getRequestHeaders();
		final Set<Entry<String, List<String>>> headerSet = requestHeaders.entrySet();
		final StringBuilder builder = new StringBuilder();
		builder.append("Http Headers:");
		builder.append("________________________________");
		builder.append("\r\n");
		for (Entry<String, List<String>> entry : headerSet) {
			builder.append(entry.getKey());
			builder.append("\t\t:");
			builder.append(entry.getValue());
			builder.append("\r\n");
		}

		return builder.toString().getBytes();
	}

	@Override
	public String getDescription() {
		return "Extract meta data information from request";
	}

	@Override
	public String getContentType() {
		return "text/plain;charset=utf-8";
	}
}
